#-*- coding: utf8 -*-
from tutor.scripts import *
from tutor.plugins.maple import *
import random

sqrt = M('sqrt')

n_iter = 0
while True:
    with display_block('Parâmetros'):
        _AA = [ M(oneof(1, 2, 3, 4, 5, 6)) * oneof(-1, 1) / oneof(1, 2, 3, 4, 5), 0, 0]
        random.shuffle(_AA)
        a, b, c = _AA
        D = sqrt(oneof(1, 2, 3, 4, 5, 6, 8, 9))
        A = M(oneof(1, 2, 3, M(1) / 2, M(3) / 2))
        B = M(oneof(1, 2, 3, M(1) / 2, M(3) / 2))
        C = M(oneof(1, 2, 3, 4, 5, 6, 8)) / oneof(1, 2, 3, 4, 5, 6, 8, 12)
        ax, by, cz = A * x, B * y, C * z
        fieldF = x * y * (a * M('_i') + b * M('_j') + c * M('_k'))

    with display_block('Resultados'):
        #TODO: refazer
        n_iter += 1
        Phi = -(D ** 4 / 24) * (A * a + B * b + C * c) / (C * A ** 2 * B ** 2)
        PhiNeg = -Phi
        PhiQ = Phi * 6
        PhiQNeg = -PhiQ
        PhiJ = (D ** 4 / 24) * (a + b + c) / (A ** 2 * B ** 2)
        PhiJNeg = -PhiJ
        PhiMod = (D ** 4 / 24) * (a + b + c) * sqrt(A ** 2 + B ** 2 + C ** 2) / (C * A ** 2 * B ** 2)
        PhiModNeg = -PhiMod

        _ans = set(map(M.abs, [Phi, PhiQ, PhiJ, PhiMod, 0]))
        if len(_ans) != 5:
            continue

        _cont = False
        for _a in _ans:
            _num, _den = M.numer(_a), M.denom(_a)
            if _num > 50 or _den > 50:
                _cont = True
        if _cont:
            continue

    break
